﻿/*
*  系统设置HOME
*/

var settingModel = angular.module("settingModel", ['angularFileUpload', 'Common','loadModule'])
settingModel.controller("settingController", ['$scope', 'sysUserInfo', '$state', '$rootScope', "T", function ($scope, sysUserInfo, $state, $rootScope, T) {
    $scope.powerLv = sysUserInfo.getuserinfo().powerLV;
    $rootScope.groupName = "";
    $scope.playUrl = function (url, name) {
        $rootScope.secparstr = url;
        $rootScope.groupName = name;
        $state.go($rootScope.secparstr);
    }
    $scope.childobj = function () {         // 获取子导航
        var obj;
        angular.forEach($rootScope.rootscopeauthority, function (data, index, array) {
            if (data.id == '21135c76a133ee15cbc6fe7018213f3a') {
                obj = data;
            }
        });
        return obj;
    }
    $scope.personnelauthority = $scope.childobj().childroute;

    $scope.settingList = [];


    //第一次遍历，取出相同组的设置
    $scope.personnelauthority.forEach(function (data, index) {
        var list = { title: "", list: [], index: 0 };
        if (data.group.length > 0) {
            //遍历是否存在
            var isIn = false;
            $scope.settingList.forEach(function (data2, index2) {
                if (data2.title == data.group) {
                    isIn = true;
                }
            });
            //不存在，向数组添加这个组
            if (!isIn) {
                list.title = data.group;
                $scope.settingList.push(list);
            }
        }
    });
    //第二次遍历，向组里放入对应 的数据
    $scope.settingList.forEach(function (data, index) {
        if (data.title == "baseSet") {
            data.index = 0;
        } else if (data.title == "userSet") {
            data.index = 1;
        } else if (data.title == "individualizationset") {
            data.index = 1;
        } else if (data.title == "functionset") {
            data.index = 2;
        } else if (data.title == "systemset") {
            data.index = 3;
        } else if (data.title == "otherset") {
            data.index = 4;
        } else {
            data.index = 5;
        }
        $scope.personnelauthority.forEach(function (data2, index2) {
            if (data2.group == data.title) {
                data.list.push(data2);
            }
        });
    });

    if ($rootScope.secparstr == null || $rootScope.secparstr.length <= 0) {
        $scope.settingList.sort(function (obj1, obj2) {
            return obj1.index - obj2.index;
        });
        $rootScope.secparstr = $scope.settingList[0].list[0].name;
    }
    $scope.playUrl($rootScope.secparstr);
} ]);